home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 287_02 / prt.asm < prev    next >
Assembly Source File  |  1989-05-23  |  4KB  |  121 lines

  1.         TITLE   PRT    of GDS
  2.         page    60,132
  3.         .SFCOND
  4. ;
  5. ; *=============================================================*
  6. ; *                                                             *
  7. ; *    This file contain low level functions for printing       *
  8. ; *    functions include:                                       *
  9. ; *     prt     convert a 8 integer array for printing          *
  10. ; *     pbflush flush every thing in buffer to printer          *
  11. ; *     rmv0    remove trailing zeroes                          *
  12. ; *                                                             *
  13. ; *=============================================================*
  14.  
  15. IFDEF   COLOR
  16.   IFDEF HERC
  17.    .err both display type defined
  18.   ENDIF
  19. else
  20.   IFNDEF HERC
  21.     HERC equ 0
  22.   ENDIF
  23. ENDIF
  24.  
  25. smo     equ     4       ; small model offset value
  26.  
  27. DGROUP  group   _DATA
  28. _DATA   segment word public 'DATA'
  29.         assume  ds:DGROUP
  30.         extrn   _PBPTR:word, _PBCOUNT:word, _CFBUF:byte
  31.  
  32. _DATA   ends
  33.  
  34. _TEXT   segment byte public 'CODE'
  35.         assume  cs:_TEXT,ds:DGROUP
  36.         public  _prtc, _pbflush
  37.         public  _rmv0
  38.  
  39.         extrn   $calc:near
  40.  
  41. ;
  42. ;  prtc(ch);
  43. ;  char ch;
  44. ;
  45. ;  append the character ch to the buffer
  46. ;
  47. _prtc   proc    near    ;public to c
  48.         push    bp
  49.         mov     bp,sp
  50.         mov     bx,_PBPTR       ; load pointer
  51.         mov     dx,[bp+smo]     ; load data
  52.         mov     [bx],dl         ; append to the buffer
  53.         inc     word ptr _PBPTR ; update pointer
  54.         inc     _PBCOUNT        ; update length count
  55.         pop     bp
  56.         ret
  57. _prtc  endp
  58.  
  59. ;
  60. ;  pbflush();
  61. ;
  62. ;  flush buffer to the printer
  63. _pbflush proc    near    ;public to c
  64.         push    bp
  65.         push    ds      ; avoid ds being affected
  66.         mov     cx,_PBCOUNT
  67.         mov     bx,offset DGROUP:_CFBUF
  68.         mov     word ptr _PBPTR,bx
  69.         mov     _PBCOUNT,0
  70.         test    cx,cx
  71.         jz      pbf2
  72.         mov     dx,0
  73. pbf1:   mov     al,[bx]
  74.         xor     ah,ah
  75.         int     17h     ; use BIOS call
  76.         and     ah,29h
  77.         jnz     pbf2
  78.         inc     bx
  79.         loop    pbf1    ; loop until all printed
  80. pbf2:   pop     ds
  81.         pop     bp
  82.         ret
  83. _pbflush endp
  84.  
  85. ; rmv0(header_length);
  86. ; int header_length;
  87. ;
  88. ; remove trailing zero and return new length
  89. ; if new length is less than or equal to header length, header will be removed
  90. _rmv0   proc    near    ;public to c
  91.         push    bp
  92.         mov     bp,sp
  93.         mov     cx,_PBCOUNT
  94.         mov     dx,[bp+smo]     ; load header length
  95.         mov     bx,word ptr _PBPTR      ; load current pointer
  96. op1:    dec     bx              ; looks back
  97.         mov     al,[bx]         ; 
  98.         test    al,al           ; test for zero
  99.         jnz     short op2       ; jump if not zero
  100.         dec     cx              ; else continue
  101.         cmp     cx,dx           ; end of search if current length < header len
  102.         ja      op1
  103.         mov     dx,offset DGROUP:_CFBUF
  104.         mov     word ptr _PBPTR,dx      ; reset pointer
  105.         mov     ax,0            ; clear count
  106.         mov     _PBCOUNT,ax
  107.         pop     bp
  108.         ret                     ; return 0
  109. op2:    inc     bx              ; 
  110.         mov     word ptr _PBPTR,bx      ; update pointer and count
  111.         mov     _PBCOUNT,cx
  112.         sub     cx,dx
  113.         mov     ax,cx
  114.         pop     bp
  115.         ret                     ; return new length
  116. _rmv0   endp
  117.  
  118. _TEXT   ends
  119.         end
  120.  
  121.